import java.util.HashSet;
import java.util.Set;

public class Solution {
    public int findRepeatNumber(int[] nums) {
        int n = nums.length;
        int[] temp = new int[n];
        for (int num : nums) {
            temp[num]++;
            if (temp[num] >= 2) {
                return num;
            }

        }
        return 0;
    }

    public int findRepeatNumber2(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            if (!set.add(num)) {
                return num;
            }
        }
        return 0;
    }

}
